package test.fingers;
/**
 * @author Jesse McCane
 * @author Berkley Shands
 */

/*
 * This Class sorts a players hand byt suit and card rank
 */

import java.util.ArrayList;

public class Sort{
	public static ArrayList<Card> sortHand(ArrayList<Card> theirHand){
		ArrayList<Card> ret = theirHand;
		for(int i = 0; i < ret.size() - 1; i++){
			int pos = findMinPos(ret, i);
			swap(ret, i, pos);
		}

		return ret;
	}

	private static int findMinPos(ArrayList<Card> a, int pos){
		for(int i = pos + 1; i < a.size(); i++){
			if(a.get(i).getSortVal() > a.get(pos).getSortVal()){
				pos = i;
			}
		}
		return pos;
	}

	private static void swap(ArrayList<Card> a, int pos1, int pos2){
		Card temp = a.get(pos1);
		a.set(pos1, a.get(pos2));
		a.set(pos2, temp);
	}
}
